package com.ruoyi.pipe.cctv.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.pipe.cctv.domain.BizPipeCctv;
import com.ruoyi.pipe.cctv.service.IBizPipeCctvService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 管网cctv检测结果数据表
 * @author breeze
 * @date 2022-11-29
 */
@RestController
@RequestMapping("/cctv")
public class BizPipeCctvController extends BaseController{
    
    @Autowired
    private IBizPipeCctvService bizPipeCctvService;

    /**
     * 多条件查询cctv检测结果列表
     */
    @GetMapping("/list")
    public TableDataInfo<?> list(BizPipeCctv bizPipeCctv){
        startPage();
        List<BizPipeCctv> list = bizPipeCctvService.selectBizPipeCctvList(bizPipeCctv);
        return getDataTable(list);
    }
    
    /**
     * 查询存在问题的cctv检测结果列表
     */
    @GetMapping("/fault/list")
    public TableDataInfo<?> listFault(BizPipeCctv bizPipeCctv){
        startPage();
        List<BizPipeCctv> list = bizPipeCctvService.selectBizPipeCctvFaultList(bizPipeCctv);
        return getDataTable(list);
    }

    /**
     * 缺陷评估统计数据
     */
    @GetMapping("/fault/groupby/evaluate")
    public TableDataInfo<?> listFaultEvaluate(BizPipeCctv bizPipeCctv){
        List<Map<String,Object>> list = bizPipeCctvService.selectFaultEvaluate(bizPipeCctv);
        return getDataTable(list);
    }
    
    /**
     * 根据id获取单条cctv检测结果
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(bizPipeCctvService.selectBizPipeCctvById(id));
    }

    /**
     * 新增单条cctv检测结果
     */
    @Log(title = "官道网络cctv检测结果数据表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPipeCctv bizPipeCctv){
    	bizPipeCctv.setCreateTime(new Date());
    	bizPipeCctv.setCreateBy(SecurityUtils.getUsername());
        return toAjax(bizPipeCctvService.save(bizPipeCctv));
    }

    /**
     * 修改单条cctv检测结果
     */
    @PutMapping
    public AjaxResult edit(@RequestBody BizPipeCctv bizPipeCctv){
    	bizPipeCctv.setUpdateTime(new Date());
    	bizPipeCctv.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(bizPipeCctvService.updateById(bizPipeCctv));
    }

    /**
     * 批量删除cctv检测结果
     * 传入@PathVariable的格式类似为/1,2,3,4,5时,会自动转为数组
     */
    @Log(title = "官道网络cctv检测结果数据表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(bizPipeCctvService.removeByIds(Arrays.asList(ids)));
    }
    
    /**
     * 导出管网cctv检测结果数据表列表
     */
    @Log(title = "管网cctv检测结果数据表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizPipeCctv bizPipeCctv){
        List<BizPipeCctv> list = bizPipeCctvService.selectBizPipeCctvList(bizPipeCctv);
        ExcelUtil<BizPipeCctv> util = new ExcelUtil<BizPipeCctv>(BizPipeCctv.class);
        util.exportExcel(response, list, "管网cctv检测结果数据表数据");
    }
}
